package com.ceiling.controller;

import com.ceiling.bean.BaseRespVo;
import com.ceiling.bean.system.Admin;
import com.ceiling.bean.system.Role;
import com.ceiling.bean.system.bo.AdminCreateBo;
import com.ceiling.bean.system.bo.AdminReq;
import com.ceiling.bean.system.bo.LogAndRoleReq;
import com.ceiling.bean.system.vo.*;
import com.ceiling.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("admin")
public class SystemController {

    @Autowired
    SystemService systemService;

    @RequestMapping("admin/list")
    public BaseRespVo adminList(AdminReq adminReq){

        BaseData<Admin> adminBaseData = systemService.selectAdminList(adminReq);
        return BaseRespVo.ok(adminBaseData);
    }

    @RequestMapping("role/options")
    public BaseRespVo adminOptions(){
        List<AdminListOptionsVo> options = systemService.queryRole();
        return BaseRespVo.ok(options);
    }

    @RequestMapping("admin/create")
    public BaseRespVo adminCreate(@RequestBody Admin admin){
        int result = systemService.createAdmin(admin);
        if(result == 200){
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail();
    }

    @RequestMapping("admin/update")
    public BaseRespVo adminUpdate(@RequestBody Admin admin){
        int result = systemService.updateAdmin(admin);
        if(result == 200){
            Admin resultAdmin = systemService.selectAdminById(admin.getId());
            return BaseRespVo.ok(resultAdmin);
        }
        return BaseRespVo.fail();
    }

    @RequestMapping("admin/delete")
    public BaseRespVo adminDelete(@RequestBody Admin admin){
        int result = systemService.deleteAdmin(admin);

        return BaseRespVo.ok();
    }

    @RequestMapping("log/list")
    public BaseRespVo logList(LogAndRoleReq logReq){
        AdminLogVo adminLogVo = systemService.selectLog(logReq);
        return BaseRespVo.ok(adminLogVo);
    }

    @RequestMapping("role/list")
    public BaseRespVo roleList(LogAndRoleReq roleReq){
        AdminRoleVo adminRoleVo = systemService.selectRoleList(roleReq);
        return BaseRespVo.ok(adminRoleVo);
    }

    @RequestMapping("role/create")
    public BaseRespVo roleCreate(@RequestBody Role role){
        RoleCreateVo roleCreateVo = systemService.createRole(role);
        return BaseRespVo.ok(roleCreateVo);
    }

    @RequestMapping("role/update")
    public BaseRespVo roleUpdate(@RequestBody Role role){
        int result = systemService.updateRole(role);
        if(result == 200){
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail();
    }

//    @RequestMapping("role/delete")
//    public BaseRespVo roleDelete(@RequestBody Role role){
//        int result = systemService.deleteRole(role);
//        if(result == 200){
//            return BaseRespVo.ok();
//        }
//        return BaseRespVo.fail();
//
//    }

}
